names(IRdata )
IRdata %>% dplyr::mutate(Z = pop*gdppc)
IRdata %>% dplyr::mutate(Z = pop*gdppc) %>% ggplot(aes(x =pop, y = gdppc)) + geom_tile(aes(fill = Z))
x <- LETTERS[1:20]
y <- paste0("var", seq(1,20))
data <- expand.grid(X=x, Y=y)
data$Z <- runif(400, 0, 5)
# Heatmap
ggplot(data, aes(X, Y, fill= Z)) +
geom_tile()
View(data)
IRdata %>% dplyr::mutate(Z = pop*gdppc) %>% ggplot(aes(x =pop, y = gdppc)) + geom_tile(aes(fill = Z)) +  scale_fill_continuous(guide = "colourbar")
library(correlation)
install.packages("correlation")
library(correlation)
data <- simulate_simpson(n=100, groups=10)
View(data)
library(ggplot2)
ggplot(data, aes(x=V1, y=V2)) +
geom_point() +
geom_smooth(colour="black", method="lm", se=FALSE) +
theme_classic()
#Simple correlation
correlation(data)
ggplot(data, aes(x=V1, y=V2)) +
geom_point(aes(colour=Group)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
geom_smooth(colour="black", method="lm", se=FALSE) +
theme_classic()
correlation(data, multilevel = TRUE)
View(data)
simulate_simpson
##
library(dplyr)
data$Group
data2 <- data %>%
dplyr::mutate(team = ifelse(Group == "A" | Group == "B" | Group == "C", "Team A", NA)) %>%
dplyr::mutate(team = ifelse(Group == "D" | Group == "E" | Group == "F", "Team B", team))%>%
dplyr::mutate(team = ifelse(Group == "G" | Group == "H" | Group == "I" | Group == "J", "Team A", team))
View(data2)
table(data2$team)
data2 <- data %>%
dplyr::mutate(team = ifelse(Group == "A" | Group == "B" | Group == "C", "Team A", NA)) %>%
dplyr::mutate(team = ifelse(Group == "D" | Group == "E" | Group == "F", "Team B", team))%>%
dplyr::mutate(team = ifelse(Group == "G" | Group == "H" | Group == "I" | Group == "J", "Team C", team))
table(data2$team)
ggplot(data, aes(x=V1, y=V2)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
facet_wrap(~team) +
theme_classic()
ggplot(data, aes(x=V1, y=V2)) +
geom_line(aes(colour=Group), method="lm", se=FALSE) +
facet_wrap(~team) +
theme_classic()
ggplot(data, aes(x=V1, y=V2)) +
geom_line(aes(colour=Group), method="lm", se=FALSE)
ggplot(data, aes(x=V1, y=V2, colour=Group)) +
geom_line()
ggplot(data, aes(x=V1, y=V2, colour=Group)) +
geom_line() +
facet_wrap(~ team)
ggplot(data2, aes(x=V1, y=V2, colour=Group)) +
geom_line() +
facet_wrap(~ team) +
theme_classic()
ggplot(data2, aes(x=V1, y=V2)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
facet_wrap(~ team) +
theme_classic()
ggplot(data2, aes(x=V1, y=V2)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
facet_wrap(~ team)
ggplot(data, aes(x=V1, y=V2)) +
geom_point(aes(colour=Group)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
geom_smooth(colour="black", method="lm", se=FALSE) +
theme_classic()
ggplot(data, aes(x=V1, y=V2)) +
geom_point(aes(colour=Group)) +
geom_smooth(aes(colour=Group), method="lm", se=FALSE) +
geom_smooth(colour="black", method="lm", se=FALSE)
rm(list = ls())
library(bookdown)
install.packages("bookdown")
library(bookdown)
install.packages("modelsummary")
install.packages("likert")
help(likert)
??likert
library(likert)
help(likert)
data(pisaitems)
items29 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST25Q']
names(items29) <- c("Magazines", "Comic books", "Fiction",
"Non-fiction books", "Newspapers")
l29 <- likert(items29)
summary(l29)
plot(l29)
View(l29)
View(items29)
View(pisaitems)
View(items29)
summary(items29)
libs <- c('dplyr', 'tibble',      # wrangling
'stringr', 'readr',     # strings, input
'lubridate', 'tidyr',   # time, wrangling
'knitr', 'kableExtra',  # table styling
'ggplot2', 'viridis',   # visuals
'gganimate', 'sf',      # animations, maps
'ggthemes')             # visuals
invisible(lapply(libs, library, character.only = TRUE))
install.packages("kableExtra")
invisible(lapply(libs, library, character.only = TRUE))
## get data
infile <- "https://opendata.arcgis.com/datasets/dd4580c810204019a7b8eb3e0b329dd6_0.csv"
covid_de <- read_csv(infile, col_types = cols())
View(covid_de)
covid_de %>%
select(state = Bundesland,
county = Landkreis,
age_group = Altersgruppe,
gender = Geschlecht,
cases = AnzahlFall,
deaths = AnzahlTodesfall,
recovered = AnzahlGenesen,
date = Meldedatum)
covid_de %>%
select(state = Bundesland,
county = Landkreis,
age_group = Altersgruppe,
gender = Geschlecht,
cases = AnzahlFall,
deaths = AnzahlTodesfall,
recovered = AnzahlGenesen,
date = Meldedatum) %>%
mutate(date = date(date)) %>%
mutate(age_group = str_remove_all(age_group, "A"))
help(case_when)
covid_de %>%
select(state = Bundesland,
county = Landkreis,
age_group = Altersgruppe,
gender = Geschlecht,
cases = AnzahlFall,
deaths = AnzahlTodesfall,
recovered = AnzahlGenesen,
date = Meldedatum) %>%
mutate(date = date(date)) %>%
mutate(age_group = str_remove_all(age_group, "A")) %>%
mutate(age_group = case_when(
age_group == "unbekannt" ~ NA_character_,
age_group == "80+" ~ "80-99",
TRUE ~ age_group
)) %>%
mutate(gender = case_when(
gender == "W" ~ "F",
gender == "unbekannt" ~ NA_character_,
TRUE ~ gender
))
source("ISA2019/ggCirc.R")
library(postregplots)
library(tidyr)
library(ggplot2)
library(ggthemes)
library(viridis)
library(ggridges)
library(readr)
library(dplyr)
library(plyr)
library(data.table)
library(countrycode)
library("statnet")  # version 2016.9 with ergm 3.7.1
library("texreg")   # version 1.36.23
library("xergm")    # version 1.8.2 with btergm 1.9.0 and xergm.common 1.7.7
library(purrr)
library(amen)
library(abind)
library(plm)
load("Results/fit2_ongoing.RDta")
source("ISA2019/ggCirc.R")
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)
View(data)
ggplot(data, aes(y=value, x=specie)) +
geom_bar(position="stack", stat="identity")
library(ggplot2)
ggplot(data, aes(y=value, x=specie)) +
geom_bar(position="stack", stat="identity")
devtools::install_github("clauswilke/ggtextures")
install.packages("ggtextures")
help(barplot)
install.packages("randomcoloR")
3*40+4*49+3*47+10*41
rm(list = ls())
setwd("~/Dropbox")
setwd("~/Dropbox/investing_peace_kyle/International Peacekeeping/final_submission/Replication_Data")
# set working directory
setwd("Replication_Data")
# Function to load packages
loadPkg=function(toLoad){
for(lib in toLoad){
if(! lib %in% installed.packages()[,1])
{install.packages(lib, repos='http://cran.rstudio.com/')}
suppressMessages( library(lib, character.only=TRUE))}}
# Load libraries
packs=c("maps", "rworldmap", "maptools", "sp", "spdep", "gstat", "MatchIt","cem",
"spatstat", "coefplot", "countrycode",  "cshapes", "arm", "stargazer","scales",
"texreg", "reshape2","ggplot2", 'foreign', 'car', 'lme4', 'dplyr', "ggmap","ggrepel",
"plotROC","pROC","purrr","tibble","magrittr","ROCR","caTools","xtable","rgdal",
"lattice","pscl","MASS")
loadPkg(packs)
# set a ggplot theme for all figures
theme_set(theme_bw())
# load the function for coefficient plot
source("coefficientplot.R")
####load data
load("data/data.RData")
m1.2 <-  bayesglm(TP_mic_yes2 ~ neighbor + invest_pre_total + tp_polity2 +tp_involv_decay + warstate_polity2 + ged_total+ log(duration+1) +
log(warstate_gdppc) + log(warstate_population) + factor(Outcome) +  peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
m2.2 <- bayesglm(TP_mic_yes2 ~ neighbor + invest_pre_total + tp_polity2 + tp_involv_decay + warstate_polity2 +ged_total+log(duration+1) +
log(warstate_gdppc) + log( warstate_population)+  neighbor*invest_pre_total +  factor(Outcome) +
peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
m3.2 <- bayesglm(TP_mic_yes2 ~ neighbor + invest_pre_total + tp_polity2 + tp_aid + tp_arms + tp_involv_decay +log(duration+1) +
warstate_polity2 + ged_total+ log(warstate_gdppc) + log( warstate_population)+ neighbor*invest_pre_total +
factor(Outcome) +
peace_month + peace_month_sq + peace_month_cub, data = data,
family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
####control for NSA
m4.2 <- bayesglm(TP_mic_yes2 ~ NSA_tp + invest_pre_total +  tp_involv_decay + warstate_polity2 + ged_total+ log(warstate_gdppc) + log(duration+1) +
log(warstate_population) + factor(Outcome) +  peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
m5.2 <- bayesglm(TP_mic_yes2 ~ NSA_tp + invest_pre_total +  tp_involv_decay + warstate_polity2 + ged_total+ log(warstate_gdppc) +log(duration+1) +
log( warstate_population) +  NSA_tp*invest_pre_total + factor(Outcome) + peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
screenreg(list(m1.2, m2.2, m3.2, m4.2, m5.2))
### ##### Online Appendix Table A2:
stage1_names3  <-  c("Intercept","TP Neighbouring","TP Wartime MICs(count)", "TP Polity2", "Postwar MIC(decay)",
"Polity2", "Count of Postwar Violence", "Conflict Duration (log)", "GDP per Capita (log)","Population (log)",
"Ceasefire", "Government Victory", "Rebel Victory", "Low Activity",
"Peace Months","Peace Months$^2$", "Peace Months$^3$",
"TP Neighbouring*TP Wartime MICs(count)",
"TP Aid", "TP Arms Transfer", "Non-state TP(=1)", "Non-state TP(=1)*TP Wartime MICs(count)")
screenreg(list(m1.2, m2.2, m3.2, m4.2, m5.2),stars = c(0.001, 0.01, 0.05, 0.1),custom.coef.names = stage1_names3)
texreg(list(m1.2, m2.2, m3.2, m4.2, m5.2), file = "Table_A2.tex", single.row=F,
# custom.model.names =c("Dependent Variable: Post-Conflict Involvement"),
stars = c(0.001, 0.01, 0.05, 0.1), booktable=TRUE,
custom.coef.names = stage1_names3, dcolumn =FALSE, use.packages = TRUE, longtable = FALSE,
scalebox = 1.0, digits = 3,
caption = "Bayesian Logistic Regression on the Post-conflict Involvement",
label ="bayestab1",
caption.above = TRUE)
### Figure 3
plot.coef(modResults = list(m1.2, m2.2, m3.2, m4.2, m5.2), data = data,
vars = c("neighbor", "NSA_tp", "tp_aid", "tp_arms","invest_pre_total", "tp_involv_decay")) +
scale_x_discrete(labels=c("TP Wartime MICs(count)", "TP Neighbouring",
"TP Neighbouring*TP Wartime MICs(count)",
"Non-state TP(=1)","Non-state TP(=1)*TP Wartime MICs(count)",
"TP Aid",  "TP Arms Transfer", "Postwar MIC(decay)"
))
ggsave("figures/Figure_3.jpeg", width = 9, height = 6)
p <- plot_interEffect(ModelResults = m3.2, n.sim = 1000, data = data,
varname1 = "neighbor", varname2 = 'invest_pre_total',val1 = 0, val2 = 20,
label = c('No Neighbouring third-party',"Neighbouring third-party"), xlabs = "Third-party Wartime MICs",
ylabs = "Pr(postwar involvement=1)",
intervals = 2, facet = F)
ggsave("figures/Figure_4a.jpeg", plot = p, width = 6, height = 6)
p2 <- plot_interEffect(ModelResults = m5.2, n.sim = 1000, data = data,
varname1 = "NSA_tp", varname2 = 'invest_pre_total',val1 = 0, val2 = 20,
label = c('State third-party',"Non-state third-party"), xlabs = "Third-party Wartime MICs",
ylabs = "Pr(postwar involvement=1)",
intervals = 2, facet = F)
ggsave("figures/Figure_4b.jpeg", plot = p2, width = 6, height = 6)
###use some basic glm models
roc1 <- glm(TP_mic_yes2 ~ tp_polity2 + warstate_polity2 + factor(Outcome) +
log(warstate_gdppc) + log( warstate_population) +
peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"))
roc2 <- glm(TP_mic_yes2 ~ neighbor +  tp_polity2 + warstate_polity2 +
log(warstate_gdppc) + log( warstate_population) + factor(Outcome)+
peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"))
## use the main model 2
roc3 <-  m3.2
##ROC plot```
pp1 <- as.vector(predict(roc1, type="response"))
Y <- roc1$model$TP_mic_yes2
p.roc1 <- roc(Y,pp1,plot = TRUE, ci=TRUE)
pp2 <- as.vector(predict(roc2, type="response"))
Y <- roc2$model$TP_mic_yes2
p.roc2 <- roc(Y,pp2,plot = TRUE, ci=TRUE)
pp3 <- as.vector(predict(roc3, type ="response"))
Y <- roc3$model$TP_mic_yes2
p.roc3 <- roc(Y,pp3,plot = TRUE, ci=TRUE)
## put together for ggplot
ModelResults = list(roc1,roc2, roc3); linetypes = c("solid", "dotted", "longdash"); interval=0.2
pred_dv =lapply(ModelResults, function(x)
FUN = predict(x, type = "response"))
Y = lapply(ModelResults, function(x) FUN = x$y)
roc = Map(function(x, y) roc(x,y), Y, pred_dv)
roc_df  = lapply(roc, function(x)
FUN= data.frame(plotx = x$specificities,
ploty = rev(x$sensitivities),
name = paste("AUC =",
sprintf("%.3f",x$auc)))) %>%
map_df(., rbind)
unique(roc_df$name)
roc_df <- roc_df %>%
mutate(model = ifelse(name == "AUC = 0.743", "GLM Controls only, AUC = 0.743", name)) %>%
mutate(model = ifelse(name == "AUC = 0.871", "GLM Neighbouring TP, AUC = 0.871", model)) %>%
mutate(model = ifelse(name == "AUC = 0.978", "Bayesglm full model, AUC = 0.978", model))
p <- ggplot(roc_df, aes(x = plotx, y = ploty, color = model, linetype = model)) +
geom_line() +
scale_colour_discrete("") +
scale_linetype_manual(name = '',
values=linetypes) +
geom_segment(aes(x = 0, y = 0, xend = 1, yend = 1), alpha = 0.5) +
scale_x_continuous(name = "False Positive Rate", expand = c(0.001,0.001)) +
scale_y_continuous(name = "True positive rate", expand = c(0.001,0.001)) +
theme_bw() +
theme(legend.position=c(.65, 0.2),
text = element_text(size=16),
axis.title.y = element_text(margin = margin(1,1,1,1)),
axis.text = element_text(size=16),
axis.title=element_text(size=16))
ggsave("figures/Figure_5.jpeg", plot = p, width = 6, height = 6)
mm3.1 <- bayesglm(TP_mic_yes2 ~ neighbor*peacekeeping_total + tp_polity2 + tp_aid + tp_arms + tp_involv_decay + log(duration+1) +
warstate_polity2 + ged_total+ log(warstate_gdppc) + log( warstate_population)+  factor(Outcome) +
peace_month +peace_month_sq + peace_month_cub, data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
mm3.2 <- bayesglm(TP_mic_yes2 ~ neighbor*mediation + tp_polity2 + tp_aid + tp_arms + tp_involv_decay +
warstate_polity2 + ged_total+ log(warstate_gdppc) + log( warstate_population)+  factor(Outcome) + log(duration+1) +
peace_month +peace_month_sq + peace_month_cub, data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
mm3.3 <- bayesglm(TP_mic_yes2 ~ neighbor*good_office_total + tp_polity2 + tp_aid + tp_arms + tp_involv_decay +
warstate_polity2 + ged_total+ log(warstate_gdppc) + log( warstate_population)+  factor(Outcome) + log(duration+1) +
peace_month +peace_month_sq + peace_month_cub, data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
mm3.4 <- bayesglm(TP_mic_yes2 ~ NSA_tp*mediation +  tp_involv_decay + warstate_polity2 + ged_total+ log(warstate_gdppc) +log(duration+1) +
log( warstate_population) + factor(Outcome) +  peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
mm3.5 <- bayesglm(TP_mic_yes2 ~ NSA_tp*good_office_total +  tp_involv_decay + warstate_polity2 + ged_total+ log(warstate_gdppc) +log(duration+1) +
log( warstate_population) + factor(Outcome) +  peace_month +peace_month_sq + peace_month_cub,
data = data, family = binomial(link = "logit"), prior.scale=2.5, prior.df=1)
# ################################################### Figure 6
plot.coef(modResults = list(mm3.1, mm3.2, mm3.3, mm3.4, mm3.5), data = data,
vars= c("neighbor", "NSA_tp", "tp_aid", "tp_arms","peacekeeping_total", "tp_involv_decay",
"mediation", "good_office_total")) +
scale_x_discrete(labels=c("TP Wartime Good Office(count)",
"TP Wartime Mediation(count)",
"TP Neighbouring",
"TP Neighbouring*TP Wartime Good Office(count)",
"TP Neighbouring*TP Wartime Mediation(count)",
"TP Neighbouring*TP Wartime Peacekeeping(count)",
"Non-state TP(=1)",
"Non-state TP(=1)*TP Wartime Good Office(count)",
"Non-state TP(=1)*TP Wartime Mediation(count)",
"TP Wartime Peacekeeping(count)",
"TP Aid", "TP Arms Transfer",  "Postwar MIC(decay)"
))
ggsave("figures/Figure_6.jpeg", width = 10, height = 6)
stage2_names3  <-  c("Intercept","TP Neighbouring","TP Wartime Peacekeeping(count)","TP Neighbouring*TP Wartime Peacekeeping(count)",
"TP Polity2", "TP Aid", "TP Arms Transfer","Postwar MIC(decay)", "Conflict Duration (log)",
"Polity2", "Count of Postwar Violence", "GDP per Capita (log)","Population (log)",
"Ceasefire", "Government Victory", "Rebel Victory", "Low Activity",
"Peace Months","Peace Months$^2$", "Peace Months$^3$",
"TP Wartime Mediation (count)", "TP Neighbouring*TP Wartime mediation(count)",
"TP Wartime Good office(count)","TP Neighbouring*TP Wartime Good Office(count)",
"Non-state TP(=1)", "Non-state TP(=1)*TP Wartime Mediation(count)",
"Non-state TP(=1)*TP Wartime Good Office(count)")
texreg(list(mm3.1, mm3.2, mm3.3, mm3.4, mm3.5), file = "Table_A3.tex", single.row=F,
stars = c(0.001, 0.01, 0.05, 0.1), booktable=TRUE,
custom.coef.names = stage2_names3, dcolumn =FALSE, use.packages = TRUE, longtable = FALSE,
scalebox = 1.0, digits = 3,
caption = "Bayesian Logistic Regression on the Post-conflict Involvement (Types of Involvement)",
label ="bayestab3",
caption.above = TRUE)
## Appendix Table A1: Descriptive statistics
###discriptive table
tableA1 <- data[c("TP_mic_yes2","neighbor","invest_pre_total", "tp_polity2", "tp_involv_decay","duration","Outcome",
"warstate_polity2", "warstate_gdppc","warstate_population","peace_month","tp_aid","tp_arms",
"NSA_tp", "good_office_total","peacekeeping_total", "ged_total", "type_of_talks2_total")]
tableA1 <- tableA1 %>%
dplyr::mutate(Outcome = as.integer(Outcome)) %>%
dplyr::mutate(agreement  = ifelse(Outcome==1 & !is.na(Outcome), 1, 0),
ceasefire  = ifelse(Outcome==2 & !is.na(Outcome), 1, 0),
govwin  = ifelse(Outcome==3 & !is.na(Outcome), 1, 0),
rebelvin  = ifelse(Outcome==4 & !is.na(Outcome), 1, 0),
lowacti  = ifelse(Outcome==5 & !is.na(Outcome), 1, 0)) %>%
select(-Outcome)
tableA1 <- as.data.frame(tableA1)
stargazer(tableA1,
title="Descriptive statistics (Third-party Post-conflict Month Level)", label = "Descriptive2",
covariate.labels=c("Post-Conflict Involvement","TP Neighbouring","TP wartime MICs(count)","TP Polity2","Postwar MIC(decay)", "Conflict duration",
"Polity2",  "GDP per capita","Population", "Peace Months",
"TP Aid", "TP Arms Transfer", "Non-State TP(=1)", "TP wartime good office(count)", "TP wartime peacekeeping(count)",
"Number of Postwar Violence","TP wartime Indirect Talk(count)",
"Peace agreement", "Ceasefire", "Government Victory", "Rebel Victory", "Low Activity"),
type = "latex", digits=1, out="Table_A1.tex")
#####
load("data/third_parties_data.RData")
###discriptive table: Table B1 actor level N = 179
stargazer(third_parties[c("post_tp", "wartime_tp",  "neighbors", "aid_country", "arm_third")],
title="Descriptive statistics (Third-party level)", label = "Descriptive1",
covariate.labels=c("Post-Conflict Involvement", "Wartime Involvement Experience", "Neighbors", "Aid Donors", "Arm Supplier"),
type = "latex", digits=1, out="Table_B1.tex")
## Model: Table B2
m <- glm(post_tp ~ wartime_tp + neighbors + aid_country + arm_third, data =third_parties, family =binomial(link = "logit"))
tp_level_name <- c("Intercept", "Wartime Involvement Experience", "Neighbors", "Aid Donors", "Arm Supplier")
texreg(m, file = "Table_B2.tex", single.row=F,
custom.model.names =c("Dependent Variable: Post-Conflict Involvement"),
stars = c(0.001, 0.01, 0.05, 0.1), booktable=TRUE,
custom.coef.names = tp_level_name, dcolumn =FALSE, use.packages = TRUE, longtable = FALSE,
scalebox = 1.0,
digits = 3, caption = "Logistic Regression on the Post-conflict Involvement (Third-party level)",label ="tab1",
caption.above = TRUE)
load("./CleanData/tp_conflict_month.RData")
rm(list = ls())
load("/Users/chongchen/Dropbox/investing_peace_kyle/clean_data/tp_conflict_month.RData")
tp_post_conflict_month <- tp_conflict_month %>% dplyr::filter(PostWar_yes ==1)
library(dplyr)
tp_post_conflict_month <- tp_conflict_month %>% dplyr::filter(PostWar_yes ==1)
##############################################create decay function for mic_no
tp_post_conflict_month  <- tp_post_conflict_month  %>% dplyr::group_by(third_party, conflict_id)%>%
dplyr::arrange(third_party, conflict_id, month.id)%>% dplyr::mutate(decay.id = row_number())
load("/Users/chongchen/Dropbox/investing_peace_kyle/CleanData/tp_post_conflict_month.RData")
##############################################create decay function for mic_no
tp_post_conflict_month  <- tp_post_conflict_month  %>% dplyr::group_by(third_party, conflict_id)%>%
dplyr::arrange(third_party, conflict_id, month.id)%>% dplyr::mutate(decay.id = row_number())
load("/Users/chongchen/Dropbox/investing_peace_kyle/CleanData/tp_conflict_month.RData")
tp_post_conflict_month <- tp_conflict_month %>% dplyr::filter(PostWar_yes ==1)
##############################################create decay function for mic_no
tp_post_conflict_month  <- tp_post_conflict_month  %>% dplyr::group_by(third_party, conflict_id)%>%
dplyr::arrange(third_party, conflict_id, month.id)%>% dplyr::mutate(decay.id = row_number())
View(tp_post_conflict_month)
###create third-pary-conflict_id group
tp_post_conflict_month$group <- with(tp_post_conflict_month, paste(third_party, conflict_id, sep = "-"))
#####create empty list to store transformed variable
decaylist2 = list()
View(tp_post_conflict_month)
decaylist <- split(tp_post_conflict_month$mic_no, tp_post_conflict_month$group)
decaylist
length(decaylist)
tp_post_conflict_month$group
###group == "222-49" only has one row which cannot work for the loop
post_conflict_month2  <- post_conflict_month %>% dplyr::filter(group != "222-49")
load("/Users/chongchen/Dropbox/investing_peace_kyle/CleanData/post_conflict_month.RData")
View(post_conflict_month)
###group == "222-49" only has one row which cannot work for the loop
post_conflict_month2  <- post_conflict_month %>% dplyr::filter(group != "222-49")
#####create empty list to store transformed variable
decaylist2 = list()
decaylist <- split(post_conflict_month2$mic_no_both_period, post_conflict_month2$group)
decaylist
length(decaylist)
j = 1
length(decaylist[[j]])
0.94^{12}
0.94^(12)
0.94^(24)
0.94^(1)
0.94^(2)
0.94^(3)
C = 1
N = 1
1 + 1*0.94^{1}
j = 1
decaylist[[j]]
i 1
i =1
decaylist[[j]][i+1]
decaylist[[j]][i+1]
decaylist[[j]][i]
decaylist[[j]][i]*(0.94)^{i}
decaylist[[j]][i+1] = decaylist[[j]][i+1] + decaylist[[j]][i]*(0.94)^{i}
decaylist[[j]][i+1]
decaylist[[j]]
for (i in 1: (length(decaylist[[j]])-1)){
decaylist[[j]][i+1] = decaylist[[j]][i+1] + decaylist[[j]][i]*(0.94)^{i}
decaylist2[[j]] <- decaylist[[j]] %>%
dplyr::as_data_frame()%>%
dplyr::mutate(group2 = names(decaylist)[j],
decay.id2 = row_number())
}
View(decaylist2)
decay_mic_both = do.call(rbind, decaylist2)
View(decay_mic_both)
1*0.94^{12}
exp(-0.05776)
exp(-0.05776)*1
decaylist
t = 1
t*(0.94)^{1}
i = seq(1, 12)
i
t*(0.94)^{i}
i = seq(1, 23)
i
t*(0.94)^{i}
i = seq(1, 24)
i
t*(0.94)^{i}
exp(-.0112331)
exp(−.05776227)
exp(-.05776227)
t*(0.9438743)^{i}
t*(0.9443)^{i}
t
0*(0.9443)^{i}
2*(0.9443)^{i}
2*(0.945)^{i}
2*(0.9434)^{i}
